package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CourseMedia;
import com.ruoyi.system.service.ICourseMediaService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课节视频Controller
 * 
 * @author ruoyi
 * @date 2025-05-20
 */
@DataSource(DataSourceType.SLAVE_COURSE)
@RestController
@RequestMapping("/system/media")
public class CourseMediaController extends BaseController
{
    @Autowired
    private ICourseMediaService courseMediaService;

    /**
     * 查询课节视频列表
     */
    @PreAuthorize("@ss.hasPermi('system:media:list')")
    @GetMapping("/list")
    public TableDataInfo list(CourseMedia courseMedia)
    {
        startPage();
        List<CourseMedia> list = courseMediaService.selectCourseMediaList(courseMedia);
        return getDataTable(list);
    }

    /**
     * 导出课节视频列表
     */
    @PreAuthorize("@ss.hasPermi('system:media:export')")
    @Log(title = "课节视频", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CourseMedia courseMedia)
    {
        List<CourseMedia> list = courseMediaService.selectCourseMediaList(courseMedia);
        ExcelUtil<CourseMedia> util = new ExcelUtil<CourseMedia>(CourseMedia.class);
        util.exportExcel(response, list, "课节视频数据");
    }

    /**
     * 获取课节视频详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:media:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(courseMediaService.selectCourseMediaById(id));
    }

    /**
     * 新增课节视频
     */
    @PreAuthorize("@ss.hasPermi('system:media:add')")
    @Log(title = "课节视频", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CourseMedia courseMedia)
    {
        return toAjax(courseMediaService.insertCourseMedia(courseMedia));
    }

    /**
     * 修改课节视频
     */
    @PreAuthorize("@ss.hasPermi('system:media:edit')")
    @Log(title = "课节视频", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CourseMedia courseMedia)
    {
        return toAjax(courseMediaService.updateCourseMedia(courseMedia));
    }

    /**
     * 删除课节视频
     */
    @PreAuthorize("@ss.hasPermi('system:media:remove')")
    @Log(title = "课节视频", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(courseMediaService.deleteCourseMediaByIds(ids));
    }
}
